package com.mohansever.common;

import org.json.JSONObject;

public class WxLogin {
	private String openid;
	private String session_key;
	private String unionid;
	
	public String getOpenid() {
		return openid;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}
	public String getSession_key() {
		return session_key;
	}
	public void setSession_key(String session_key) {
		this.session_key = session_key;
	}
	public String getUnionid() {
		return unionid;
	}
	public void setUnionid(String unionid) {
		this.unionid = unionid;
	}
	
	public boolean paserOpenId(String jsonStr){
		System.out.println("jsonStr = " + jsonStr);
		
		JSONObject obj = new JSONObject(jsonStr);	
		if(obj.has("errcode")){
			return false;
		}else{
			if (obj.has("openid")) {
				this.openid = obj.getString("openid");
			}else{
				return false;
			}
			if(obj.has("session_key")){
				this.session_key = obj.getString("session_key");
			}else{
				return false;
			}
			if(obj.has("UNIONID")){
				this.unionid = obj.getString("UNIONID");
			}else{
				return false;
			}
		}
		
		return true;
	}
}
